﻿/*************************
 * 操作单机数据库
****************************/

using System.Data;
using System.Collections.Generic;
using Saturn.AppSQLite;
using System.Data.SQLite;
using System;
using System.Collections;

namespace Saturn.App.FormOper
{
    public class DataInterface
    {
        #region SysUsers
        /// <summary>
        /// 运行程序时把平台的用户信息更新到PDA的单机数据库中
        /// </summary>
        /// <param name="dtUser"></param>
        public static void GetSysUsers(DataTable dtUser)
        {
            //string strsq = "delete from sysuser";
            //SQLiteCommand cmd1 = new SQLiteCommand();

            List<string> lstSql = new List<string>();
            string strInsert = "insert into SysUser values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');";
            string userList = "";
            foreach (DataRow item in dtUser.Rows)
            {
                SQLiteCommand cmd = new SQLiteCommand();
                string userName = item["UserName"].ToString();
                if (!userList.Contains(userName))
                {
                    userList += userName + "|";

                    lstSql.Add(string.Format(strInsert, item["ID"].ToString(), item["UserName"].ToString(), item["Password"].ToString(), item["RealName"].ToString(), item["Sex"].ToString(), item["OrgCode"].ToString(), item["OrgID"].ToString(), item["OrgName"].ToString(), item["OrgCatID"].ToString(), item["OrgCatName"].ToString(), item["MainOrgID"].ToString()));
                }
            }
            if (lstSql.Count > 0)
            {
                lstSql.Insert(0, "delete from SysUser;");
            }

            // 执行
            SqliteHelper.ExecuteSqlTran(SqliteHelper.SqlConnection, lstSql);
        }
        #endregion

   
     
    }
}
